@isTest
private class IntentProductHandlerTest {

    static testMethod void testMethod1() {
        
        //客户1
        Account acc = TestUtils.createAccount();
        acc.Level__c = '三级甲等';
        insert acc;             
        
        //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        

        insert opp;

      Brand__c brand = new Brand__c(
            BrandShortName__c = '四川迈克'
        );
        insert brand;
          //产品结构
        ProductStructure__c ps1=new ProductStructure__c();
        ps1.Name='仪器';
        ps1.Classify1__c='生化';
        ps1.Classify2__c='生化-设备';
        ps1.Classify3__c='仪器';
        insert ps1;

          //产品
        Product__c p3=TestUtils.createProduct();
        p3.Name='仪器';
        p3.Category0__c = '仪器';
        p3.Model__c='Model1228';
        p3.ProductStructure__c=ps1.Id;
        p3.CRMBrand__c = brand.Id;
        p3.RecordTypeId =  Utils.getRecordTypeIdByDevNameAndObjName('CompetitorProduct','Product__c');
        insert p3;

        //产品1  
        Product__c p1 = TestUtils.createProduct();
        p1.Purpose__c = '试剂报价用';
        p1.Category1__c = '微生物';   
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c') ;
        Product__c p2 = TestUtils.createProduct();
        p2.Name = 'Test1';
        p2.Category1__c = '免疫';
        p2.Purpose__c = '试剂报价用';
        p2.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c') ;
        insert new Product__c[] {p1, p2};


         Dealer__c dl = new Dealer__c();
         dl.Name = 'dl';
         dl.Only__c = 'dl1';
         insert dl;

         Equipment__c eq=new Equipment__c();
        //eq.Name='testYQ';
        eq.Account__c=acc.Id;
        eq.Product__c=p3.Id;
        eq.Supplier__c = dl.id;
        eq.OpponentSpecialTeam__c= '生化';
        insert eq;
        System.debug('++++++++++');

        ProductProject__c pp=new ProductProject__c();
        pp.Name='项目111';
        pp.ProductStructure__c=ps1.Id;
        //pp.Brand__c='迈克生物/maccura';
        insert pp;

        AssetProject__c ap=new AssetProject__c();
        ap.Name='资产项目111';
        ap.Instrument__c = eq.id;
        ap.ProductProject__c = pp.Id;
        ap.Account__c = acc.Id;
        ap.Supplier__c = dl.Id;
        ap.Brand__c = brand.Id;
        insert ap;
       

       SpecialTeam__c st = new SpecialTeam__c();
       st.TeamType__c = '生化';
       st.Team2Dept__c =  [select Id from Department__c where TerminalCustomer__c =:acc.Id limit 1].Id;
       insert st;
        //意向产品1
        IntentProduct__c ip1 = TestUtils.createIntentProduct();
        ip1.Product__c = p1.Id;
        ip1.Opportunity__c = opp.Id;
        ip1.Comment__c = 'Tste===============';
        ip1.SpecialTeam__c =  st.Id;
        IntentProduct__c ip2 = TestUtils.createIntentProduct();

        ip2.Product__c = p2.Id;
        ip2.Opportunity__c = opp.Id;   
        insert new IntentProduct__c[] {ip1, ip2};
        
        Opportunity p = [select ProjectType__c,id from Opportunity where id = :opp.Id];
        
        
        //system.debug(p.ProjectType__c);
        //system.assertEquals('多项目', p.ProjectType__c);

        ip1.Model__c = '321';
        update ip1;
        
        delete ip1;
        Opportunity deleteOpp = [select ProjectType__c,id from Opportunity where id = :opp.Id];
        //system.assertEquals('单项目', deleteOpp .ProjectType__c);
    }
    /*
    static testMethod void testMethod2() {

        //客户2
        Account acc1 = TestUtils.createAccount();
        acc1.Level__c = '二级甲等';
        acc1.Name = '测试客户1';
        insert acc1;

        //业务机会2
        Opportunity opp1 = TestUtils.createOpportunity();
        opp1.AccountId = acc1.Id;
        opp1.Name = '测试业务机会1';
        insert opp1;

        ////产品2  
        Product__c p11 = TestUtils.createProduct();
        p11.Purpose__c = '试剂报价用';
        p11.Category1__c = '微生物'; 
        p11.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c') ;

        Product__c p22 = TestUtils.createProduct();
        p22.Name = 'Test1';
        p22.Category1__c = '免疫';
        p22.Purpose__c = '试剂报价用';
        p22.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c') ;
        insert new Product__c[] {p11, p22};

        //意向产品2
        IntentProduct__c ip11 = TestUtils.createIntentProduct();
        ip11.Product__c = p11.Id;
        ip11.Opportunity__c = opp1.Id;
        ip11.Comment__c = 'Tste===============';
        IntentProduct__c ip22 = TestUtils.createIntentProduct();
        ip22.Product__c = p22.Id;
        ip22.Opportunity__c = opp1.Id;   
        insert new IntentProduct__c[] {ip11, ip22};

        Opportunity p = [select ProjectType__c,id from Opportunity where id = :opp1.Id];

        //system.assertEquals('多项目', p.ProjectType__c);

        ip11.Model__c = '321';
        update ip11;
        
        delete ip11;
        Opportunity p1 = [select ProjectType__c,id from Opportunity where id = :opp1.Id];
       // system.assertEquals('单项目',p1.ProjectType__c);




        // //产品2
        // Product__c pp1 = TestUtils.createProduct();
        // pp1.Purpose__c = '试剂报价用';
        // pp1.Category1__c = '微生物'; 
        // Product__c pp2 = TestUtils.createProduct();
        // pp2.Purpose__c = '试剂报价用';
        // pp2.Category1__c = '分子'; 
        // Product__c pp3 = TestUtils.createProduct();
        // pp3.Purpose__c = '试剂报价用';
        // pp3.Category1__c = '免疫'; 
        // Product__c pp4 = TestUtils.createProduct();
        // pp4.Purpose__c = '试剂报价用';
        // pp4.Category1__c = '生化'; 
        // Product__c pp5 = TestUtils.createProduct();
        // pp5.Purpose__c = '试剂报价用';
        // pp5.Category1__c = '血型'; 

        // insert new Product__c[] {pp1,pp2,pp3,pp4,pp5};

        // //意向产品2
        // IntentProduct__c ipp1 = TestUtils.createIntentProduct();
        // ipp1.Product__c = pp1.Id;
        // ipp1.Opportunity__c = opp.Id;
        // IntentProduct__c ipp2 = TestUtils.createIntentProduct();
        // ipp2.Product__c = pp2.Id;
        // ipp2.Opportunity__c = opp.Id;
        // IntentProduct__c ipp3 = TestUtils.createIntentProduct();
        // ipp3.Product__c = pp3.Id;
        // ipp3.Opportunity__c = opp.Id;
        // IntentProduct__c ipp4 = TestUtils.createIntentProduct();
        // ipp4.Product__c = pp4.Id;
        // ipp4.Opportunity__c = opp.Id;
        // IntentProduct__c ipp5 = TestUtils.createIntentProduct();
        // ipp5.Product__c = pp5.Id;
        // ipp5.Opportunity__c = opp.Id;
        // insert new IntentProduct__c[] {ipp1, ipp2, ipp3, ipp4, ipp5};    

    }*/
}